{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Word2Vec 模型之 skip gram\n",
    "\n",
    "## 问题抽象\n",
    "\n",
    "$$G = \\prod_{u \\in Context(w)} \\prod_{z \\in u \\cup NEG(u)} p(z|w)$$\n",
    "\n",
    "$$p(z|w) = (\\sigma (v(w)^T \\theta^z))^{L^u(z)} * (1 - \\sigma (v(w)^T \\theta^z))^{1 - L^u(z)}$$\n",
    "\n",
    "## 损失函数\n",
    "\n",
    "$$Loss =  \\sum_{u \\in Context(w)} \\sum_{z \\in u \\cup NEG(u)} L^u(z) * log(\\sigma (v(w)^T \\theta^z)) + (1 - L^u(z)) * log(1 - \\sigma (v(w)^T \\theta^z))$$\n",
    "\n",
    "### 优化\n",
    "\n",
    "$$G = \\prod_{u \\in Context(w)} \\prod_{z \\in u \\cup NEG(u)} p(z|w^c)$$\n",
    "\n",
    "$$Loss =  \\sum_{w^c \\in Context(w)} \\sum_{u \\in u \\cup NEG(u)} L^u(z) * log(\\sigma (v(w^c)^T \\theta^u)) + (1 - L^u(z)) * log(1 - \\sigma (v(w^c)^T \\theta^u))$$\n",
    "\n",
    "## 训练主流程\n",
    "\n",
    "- 对于context(w)中任何一个词$w^c$，选取词w的正负样本\n",
    "\n",
    "- 计算Loss对$\\theta$以及对$w^c$的偏导\n",
    "\n",
    "- 更新$w^c$对应的词向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
